<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />

<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加规格</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form1">
		<input type="hidden" name="goods_id" id="goods_id">
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>规格名称：</label>
			<div class="formControls col-4">
				<input type="text" class="input-text" value="" placeholder="" name="sku_info" datatype="*" nullmsg="规格名称不能为空">
			</div>
			<div class="col-3"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>库存：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_num" datatype="n1-16" nullmsg="库存不能为空">
			</div>
			<div class="col-3"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>价格：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_cost" datatype="*1-16" nullmsg="价格不能为空">
			</div>
			<div class="col-3"> </div>
		</div>
		<!-- <div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>团购价格：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_group_cost" datatype="*1-16" nullmsg="团购价格不能为空">
			</div>
			<div class="col-3"> </div>
		</div> -->
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>重量：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_weight" datatype="n1-16" nullmsg="重量不能为空">
			</div>
			<div class="col-3"> </div>
		</div>
		
<!-- 		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>抵扣券：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_max_quan" datatype="n1-16" nullmsg="抵扣券不能为空">
			</div>
			<div class="col-3"> </div>
		</div> -->
<!-- 		<div class="row cl">
			<label class="form-label col-3">预售数量：</label>
			<div class="formControls col-4">
				<input type="number" class="input-text" value="" placeholder="" name="sku_bespeak_num">
			</div>
			<div class="col-3"> </div>
		</div> -->

		<div class="row cl">
			<label class="form-label col-3">产品图：</label>
			<div class="formControls col-3" >
				<div class="l mb-10 fj-img" id="imgslt" >	
					<input type="hidden" name="sku_image" value="">	
				</div>	
				<i class="Hui-iconfont fj-img-btn" onclick="_open('添加附件','article-imageupload.html?type=image&idname=imgslt&api=goods&single=1&inputname=sku_image','710px','470px',true)">&#xe610;</i>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>是否启用：</label>
			<div class="formControls col-7">
				<div class="radio-box">
					
					<label><input type="radio" value="1" name="sku_state">是</label>
				</div>
				<div class="radio-box">
					
					<label><input type="radio" value="0" name="sku_state" checked>否</label>
				</div>
			</div>
			<div class="col-3"> </div>
		</div>
		
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input class="btn btn-primary radius" type="button" id="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 

<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/s.js"></script> 
<script type="text/javascript">
$("#form1").attr("action", API_GUIGE_EDIT);
var gid=getUrlParam('gid');
var editid=getUrlParam('editid');
if(gid!==null){
	$("#goods_id").val(gid);
}
if(editid!==null){
	var eidturl=API_GUIGE_EDIT+'?sku_id='+editid;
	$("#form1").attr("action", eidturl);
	$.getJSON(eidturl,function(data){
    	if(!checkStatus(data)) return;
    	
    		
    		$("input[name='sku_info']").val(data.datas.sku_info);
    		$("input[name='sku_info']").attr("readOnly","true");
    		$("input[name='sku_num']").val(data.datas.sku_num);
    		$("input[name='sku_cost']").val(data.datas.sku_cost);
    		// $("input[name='sku_group_cost']").val(data.datas.sku_group_cost);


    		$("input[name='sku_weight']").val(data.datas.sku_weight);
    		// $("input[name='sku_max_quan']").val(data.datas.sku_max_quan);
    		// $("input[name='sku_bespeak_num']").val(data.datas.sku_bespeak_num);


    		$("input[name='sku_state'][value="+data.datas.sku_state+"]").attr("checked",true);

    		if(data.datas.sku_image!==""){
            	$("#imgslt").html('<img src="'+data.datas.sku_image+'"><i class="icon Hui-iconfont fun-img-del" data-id="#imgslt" data-inputname="sku_image"></i><input type="hidden" name="sku_image" value="'+data.datas.sku_image+'">');
            }

            
        
    })
}
$(function(){
	$(document).on('click','input#submit',function(){
		// if(parseInt($("input[name='sku_max_quan']").val())>parseInt($("input[name='sku_cost']").val()) || parseInt($("input[name='sku_max_quan']").val())>parseInt($("input[name='sku_group_cost']").val())){
		// 	layer.msg("抵扣券数不能大于价格或团购价格", {icon:2,time:1000});
		// }else{

		if(parseInt($("input[name='sku_max_quan']").val())>parseInt($("input[name='sku_cost']").val())){
			layer.msg("抵扣券数不能大于价格或团购价格", {icon:2,time:1000});
		}else{
			// Validformsubmit("#form1");
			
			$("#form1").Validform({
		        tiptype:2,
		        ajaxPost:true,
		        callback:function(data){
		            if(!checkStatus(data)) return;
		            if(data.status=='1'){
		                var index = parent.layer.getFrameIndex(window.name);
		                parent.parent.layer.msg(data.info, {icon:1,time:1000});
		                // window.parent.location.reload();
						var state_state_value=$("input[name='sku_state']:checked").val();

		                var sku_state=state_state_value==1?'checked':'';

		                // 添加商品时添加规格
	                	var imgurl="/Manage/images/noimg.jpg";
	                	var ss=$("input[name='sku_image']").val();
	                	console.log("ss"+ss);
	                	if(ss!==''){
	                		
	                		if(ss.indexOf("http")>=0){
	                			imgurl=ss;
	                		}else{
	                			imgurl='https://cdn.quansuwangluo.com/wd_goods/'+ss;
	                		}
	                		
	                	}
		                	console.log(imgurl)

		                if(gid=='null'){
		                	parent.$("#model-list").append('<tr id="sku'+sku_id+'"><td class="text"></td><td class="text"><input type="text" class="input-text" value="'+$("input[name='sku_info']").val()+'" name="sku_info[]" readonly></td><td class="text"><img src="'+imgurl+'"></td><td class="text"><input type="number" class="input-text" value="'+$("input[name='sku_num']").val()+'" name="sku_num[]" readonly></td><td class="text"><input type="number" class="input-text" value="'+$("input[name='sku_cost']").val()+'" name="sku_cost[]" readonly></td></td><td class="text"><input type="number" class="input-text" value="'+$("input[name='sku_weight']").val()+'" name="sku_weight[]" readonly></td><td class="text"><label class="guige-status"><input type="checkbox" class="selectskustate" value="1">启用<input type="hidden" name="sku_state[]"></label></td><td><input type="hidden" name="sku_image[]" value="'+$("input[name='sku_image']").val()+'"></td></tr>');

		                }else{
		                	// 修改商品时添加规格
		                	if(editid==null){
			                	var sku_id=data.url;
			                	parent.$("#model-list").append('<tr id="sku'+sku_id+'"><td class="text">'+sku_id+'</td><td class="text">'+$("input[name='sku_info']").val()+'</td><td class="text"><img src="'+imgurl+'" ></td><td class="text">'+$("input[name='sku_num']").val()+'</td><td class="text">'+$("input[name='sku_cost']").val()+'</td><td class="text">'+$("input[name='sku_weight']").val()+'</td><td class="text"><label><input type="checkbox" class="editselectskustate" value="1" '+sku_state+'>启用<input type="hidden" name="sku_state[]" value="'+state_state_value+'"></label></td><td><a style="text-decoration:none" onClick="editguige('+sku_id+','+gid+')" class="ml-5 edit" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> </td></tr>');
			                }else{
			                	// 修改商品时修改规格
			                	var idname="#sku"+editid;
			                	parent.$(idname).html('<td class="text">'+editid+'</td><td class="text">'+$("input[name='sku_info']").val()+'</td><td class="text"><img src="'+imgurl+'" ></td><td class="text">'+$("input[name='sku_num']").val()+'</td><td class="text">'+$("input[name='sku_cost']").val()+'</td><td class="text">'+$("input[name='sku_weight']").val()+'</td><td class="text"><label><input type="checkbox" class="editselectskustate" value="1" '+sku_state+'>启用<input type="hidden" name="sku_state[]" value="'+state_state_value+'"></label></td><td><a style="text-decoration:none" onClick="editguige('+editid+','+gid+')" class="ml-5 edit" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> </td>');
			                }
		                }
		                
		                // window.parent.loaddata(parent.kk);
		                parent.layer.close(index); 
		                // console.log("kk:"+window.parent.kk)     
		            }
		        }
		    });
			$("#form1").submit();
		}

	})
	
	
});
</script>
</body>
</html>